package GUI;

import Kernel.Administrateur;

public class SupprimerVille extends javax.swing.JFrame {

    private static final long serialVersionUID = 1L;
	
	/** Crée une nouvelle instance de SupprimerVille */
    public SupprimerVille() {
        initComponents();
        this.setLocationRelativeTo(this.getParent());
    }

    /**
	 * Initialisation des composants d'AWT.
	 */
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        referenceVille = new javax.swing.JTextField();
        supprimer = new javax.swing.JButton();
        retour = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Supprimer une Ville");

        jLabel2.setText("Nom de la ville");

        supprimer.setText("Supprimer");
        supprimer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                supprimerActionPerformed(evt);
            }
        });

        retour.setText("Retour");
        retour.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                retourActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(131, 131, 131)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(65, 65, 65)
                        .addComponent(jLabel2)
                        .addGap(26, 26, 26)
                        .addComponent(referenceVille, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(retour)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 279, Short.MAX_VALUE)
                        .addComponent(supprimer)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(66, 66, 66)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(referenceVille, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 79, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(supprimer)
                    .addComponent(retour))
                .addContainerGap())
        );

        pack();
    }

    private void supprimerActionPerformed(java.awt.event.ActionEvent evt) {
    	Accueil.serveur.supprimerVille(Accueil.serveur.chercherVille(this.referenceVille.getText()));
    	Administration at = new Administration(new Administrateur(Administration.admin.getLogin(), Administration.admin.getPassword(), Accueil.serveur));
		at.setVisible(true);
		this.setVisible(false);
		this.dispose();
    }

    private void retourActionPerformed(java.awt.event.ActionEvent evt) {
    	Administration at = new Administration(new Administrateur(Administration.admin.getLogin(), Administration.admin.getPassword(), Accueil.serveur));
		at.setVisible(true);
		this.setVisible(false);
		this.dispose();
    }

    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField referenceVille;
    private javax.swing.JButton retour;
    private javax.swing.JButton supprimer;

}
